<template>
  <!-- 催收执行页-历史信息模块-录音历史 -->
  <section class="component record-history">
    <!-- 搜索区域 -->
    <data-form
      :model="searchModel"
      @handleResetForm="handleResetForm"
      @onSearch="refreshData"
      ref="form"
    >
      <template slot="inputs">
        <el-form-item label="通话时间" prop="recordTime">
          <el-date-picker
            :editable="false"
            placeholder="请选择日期"
            type="daterange"
            v-model="searchModel.recordTime"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="通话时长" prop="callDuration">
          <number-range
            :isInteger="true"
            v-model="searchModel.callDuration"
          ></number-range>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input
            clearable
            placeholder="客户姓名"
            v-model.trim="searchModel.personalName"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系人" prop="targetName">
          <el-input
            clearable
            placeholder="联系人"
            v-model.trim="searchModel.targetName"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="targetPhone">
          <el-input
            clearable
            placeholder="联系电话"
            v-model.trim="searchModel.targetPhone"
          ></el-input>
        </el-form-item>
      </template>
    </data-form>
    <!-- 数据列区域 -->
    <data-box
      :data="dataSet"
      :height="200"
      :page="pageService"
      @onPageChange="refreshData"
    >
      <template slot="columns">
        <el-table-column
          :min-width="$helper.getColumnWidth(4)"
          label="行动流水"
          prop="liushui"
        ></el-table-column>
        <el-table-column
          :min-width="$helper.getColumnWidth(5)"
          label="通话时间"
          prop="recordStartTime"
        ></el-table-column>
        <el-table-column
          :formatter="row => $filter.dictConvert(row.callType, 'CallType')"
          :min-width="$helper.getColumnWidth(3)"
          label="呼叫类型"
          prop="callType"
        ></el-table-column>
        <el-table-column
          :min-width="$helper.getColumnWidth(4)"
          label="联系电话"
          prop="targetPhone"
        ></el-table-column>
        <el-table-column
          :min-width="$helper.getColumnWidth(4)"
          label="通话时长(秒)"
          prop="callDuration"
        ></el-table-column>
        <el-table-column
          :formatter="
            row => $filter.dictConvert(row.phoneStatus, 'PhoneStatus')
          "
          :min-width="$helper.getColumnWidth(4)"
          label="电话状态"
          prop="phoneStatus"
        ></el-table-column>
        <el-table-column
          :min-width="$helper.getColumnWidth(10)"
          label="备注"
          prop="remark"
        ></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(6)" label="录音">
          <template slot-scope="scope">
            <el-button type="text">试听</el-button>
            <el-button type="text">下载</el-button>
          </template>
        </el-table-column>
      </template>
    </data-box>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies } from "~/core/decorator";
import { Prop } from "vue-property-decorator";
import { CaseOperatorPageService } from "~/services/domain-service/case-operator-page.service";

import { PageService } from "~/utils/page.service";
import { SortService } from "~/utils/sort.service";
import NumberRange from "~/components/common/number-range.vue";
import { namespace } from "vuex-class";

const CollectionExecutionModule = namespace("collection-execution");

@Component({
  components: {
    NumberRange
  }
})
export default class RecordHistory extends Vue {
  @Dependencies(PageService)
  private pageService: PageService;
  @Dependencies(SortService)
  private sortService: SortService;
  @Dependencies(CaseOperatorPageService)
  private caseOperatorPageService: CaseOperatorPageService;
  @CollectionExecutionModule.State private caseId;

  private searchModel: any = {
    recordTime: [],
    callDuration: {
      max: "",
      min: ""
    },
    personalName: "",
    targetName: "",
    targetPhone: ""
  };
  private dataSet: any[] = [];

  /**
   * 范围组件数据重置
   */
  private handleResetForm() {
    this.searchModel.callDuration = { min: "", max: "" };
  }

  //获取录音历史
  private refreshData() {
    this.searchModel.caseId = this.caseId;
    this.caseOperatorPageService
      .caseTelRecord(this.searchModel, this.pageService, this.sortService)
      .subscribe(data => {
        this.dataSet = data;
      });
  }

  private activated() {
    this.refreshData();
  }
}
</script>

<style lang="less"></style>
